<?php $this->load->view('layout/header'); ?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">旅游订单管理
                <small> 订单管理</small>
            </h3>
            <?php echo breadcrumb(array('旅游订单管理', 'tourismorder/grid' => '订单管理', '查看订单')); ?>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span4">
            <div class="portlet sale-summary">
                <div class="portlet-title">
                    <div class="caption">订单详情</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <ul class="unstyled">
                    <li>
                        <span class="sale-info">编号 <i class="icon-img-down"></i></span>
                        <span class="sale-num"><?php echo $orderInfo->order_id; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">订单编号 <i class="icon-img-up"></i></span>
                        <span class="sale-num"><?php echo $orderInfo->order_sn; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">支付状态</span>
                        <span class="sale-num"><?php echo $tourismOrderStateArray[$orderInfo->order_state]; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">订单状态</span>
                        <span
                            class="sale-num"><?php echo $tourismOrderStatusArray[$orderInfo->order_status]; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">购买者（用户名/UID）</span>
                        <span class="sale-num"><?php echo $orderInfo->user_name.' | '.$orderInfo->payer_uid; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">供应商UID</span>
                        <span class="sale-num"><?php echo $orderInfo->seller_uid; ?></span>
                    </li>
                    <?php $addressDetail = json_decode($orderInfo->detail);?>
                    <li>
                        <span class="sale-info">收货人姓名</span>
                        <span class="sale-num"><?php echo $addressDetail->receiver_name; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">收货人电话</span>
                        <span class="sale-num"><?php echo $addressDetail->tel; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">收货人邮编</span>
                        <span class="sale-num"><?php echo $addressDetail->code; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">收货地址</span>
                        <span class="sale-num"><?php echo $addressDetail->detailed; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">客户留言</span>
                        <span class="sale-num"><?php echo $orderInfo->message; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">发票抬头</span>
                        <span class="sale-num"><?php echo $orderInfo->vanguard;?></span>
                    </li>
                    <li>
                        <span class="sale-info">订单备注(着想员工自己插入)</span>
                        <span class="sale-num">
                           <span class="order-note-one">
                              <span><?php echo $orderInfo->order_note;?></span>
                              <a class="btn green edit-order-note" href="javascript:;">修改</a>
                           </span>
                           <span class="order-note-two" style="display:none">
                              <input type="hidden" name="order_note_id" value="<?php echo $orderInfo->order_id; ?>">
                              <input type="text"   name="order_note" value="<?php echo $orderInfo->order_note; ?>" class="m-wrap span8">
                              <a class="btn green save-order-note" href="javascript:;">保存</a>
                           </span>
                        </span>
                    </li>
                </ul>
            </div>
        </div>
        <div class="span4">
            <div class="portlet sale-summary">
                <div class="portlet-title">
                    <div class="caption">操作时间</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <ul class="unstyled">
                    <li>
                        <span class="sale-info">下单时间</span>
                        <span class="sale-num"><?php echo $orderInfo->created_at; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">支付时间</span>
                        <span class="sale-num"><?php echo $orderInfo->pay_time; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">发货时间</span>
                        <span class="sale-num"><?php echo $orderInfo->send_time; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">确认收货时间</span>
                        <span class="sale-num"><?php echo $orderInfo->receive_time; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">评价时间</span>
                        <span class="sale-num"><?php echo $orderInfo->reviews_time; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">修改时间</span>
                        <span class="sale-num"><?php echo $orderInfo->updated_at; ?></span>
                    </li>
                    <li>
                        <span class="sale-info"></span>
                        <span class="sale-num"></span>
                    </li>
                    <?php if ($orderInfo->order_status == 2) :?>
                        <?php $time = strtotime($orderInfo->created_at) - time() + 3600 * 24?>
                        <?php if ($time > 0) :?>
                            <?php
                                $days = intval($time / 86400);
                                $remain = $time % 86400;
                                $hours = intval($remain / 3600);
                                $remain = $remain % 3600;
                                $mins = intval($remain / 60);
                                $secs = $remain % 60;
                            ?>
                            <li>
                                <span class="sale-info">距离支付时间还有</span>
                                <span class="sale-num"><span><?php echo $days ?>天<?php echo $hours ?>小时<?php echo $mins ?>分</span>来支付，超时订单自动取消</span>
                            </li>
                        <?php endif;?>
                    <?php elseif ($orderInfo->order_status == 4) :?>
                        <?php $time = strtotime($orderInfo->send_time) - time() + 3600 * 24 * 7?>
                        <?php if ($time > 0) :?>
                            <?php
                                $days = intval($time / 86400);
                                $remain = $time % 86400;
                                $hours = intval($remain / 3600);
                                $remain = $remain % 3600;
                                $mins = intval($remain / 60);
                                $secs = $remain % 60;
                            ?>
                            <li>
                                <span class="sale-info">距离收货时间还有</span>
                                <span class="sale-num"><span><?php echo $days ?>天<?php echo $hours ?>小时<?php echo $mins ?>分</span>来确认收货，超时订单自动确认收货</span>
                            </li>
                        <?php endif;?>
                    <?php elseif ($orderInfo->order_status == 5) :?>
                        <?php $time = strtotime($orderInfo->receive_time) - time() + 3600 * 24 * 7?>
                        <?php if ($time > 0) :?>
                            <?php
                                $days = intval($time / 86400);
                                $remain = $time % 86400;
                                $hours = intval($remain / 3600);
                                $remain = $remain % 3600;
                                $mins = intval($remain / 60);
                                $secs = $remain % 60;
                            ?>
                            <li>
                                <span class="sale-info">距离好评时间还有</span>
                                <span class="sale-num"><span><?php echo $days ?>天<?php echo $hours ?>小时<?php echo $mins ?>分</span>来评价，超时订单将自动好评</span>
                            </li>
                        <?php endif;?>
                    <?php endif;?>
                </ul>
            </div>
        </div>
        <div class="span4">
            <div class="portlet sale-summary">
                <div class="portlet-title">
                    <div class="caption">支付信息</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <ul class="unstyled">
                    <li>
                        <span class="sale-info">支付方式<i class="icon-img-up"></i></span>
                        <span class="sale-num"><?php echo $tourismPaymentType[$orderInfo->payment_type]; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">支付银行 <i class="icon-img-down"></i></span>
                        <span class="sale-num"><?php echo $orderInfo->pay_bank == 201 ? '微信支付' : (!empty($payMethod) ? $payMethod->bank_name : '未选择'); ?></span>
                    </li>
                    <li>
                        <span class="sale-info">实际价格</span>
                        <span class="sale-num">￥<?php echo $orderInfo->actual_price; ?></span>
                    </li>
                    <li>
                        <span class="sale-info">实际支付U币</span>
                        <span class="sale-num">￥<?php echo $orderInfo->pay_swim;?></span>
                    </li>
                    <li>
                        <span class="sale-info">退款金额</span>
                        <span class="sale-num">￥<?php echo bcsub($orderInfo->actual_price, $orderInfo->order_pay_total, 2); ?></span>
                    </li>
                    <li>
                        <span class="sale-info">运费价格</span>
                        <span class="sale-num">
                        <?php if ($orderInfo->order_status == 2) :?>
                            <span class="original-price">￥
                                <span><?php echo $orderInfo->transport_cost; ?></span> 
                                <a class="btn green edit-price" href="javascript:;">修改</a>
                            </span>
                            <span class="new-price" style="display:none">
                                <input type="hidden" name="order_id" value="<?php echo $orderInfo->order_id; ?>">
                                <input type="text" name="transport_cost" value="<?php echo $orderInfo->transport_cost; ?>" class="m-wrap span8">
                                <a class="btn green save-price" href="javascript:;">保存</a>
                            </span>
                        <?php else :?>
                            <span>￥<?php echo $orderInfo->transport_cost; ?></span> 
                        <?php endif;?>
                        </span>
                    </li>
                    <li>
                        <span class="sale-info">实际支付</span>
                        <span class="sale-num">￥<?php echo bcadd($orderInfo->order_pay_total, $orderInfo->transport_cost, 2); ?></span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <?php if ( $orderInfo->order_status == 3 && $orderInfo->order_state == 2 && ( (time() - strtotime( $orderInfo->pay_time ) ) >= 43200 ) ): ?>
    <div class="portlet box green">
        <div class="portlet-title">
            <div class="caption"><i class="icon-picture"></i>发货提醒 ps:支付状态已付款 订单状态已付款 并且支付时间超过12小时才可以发送短信</div>
            <div class="tools">
                <a class="collapse" href="javascript:;"></a>
                <a class="remove" href="javascript:;"></a>
            </div>
        </div>
        <div class="portlet-body">
            <button  type="button" class="btn green send-sms-remind" data-order-id="<?php echo $orderInfo->order_id;?>">发货短信提醒</button>
        </div>
    </div>
    <?php endif ?>
    <div class="portlet box green">
        <div class="portlet-title">
            <div class="caption"><i class="icon-picture"></i>购买的产品</div>
            <div class="tools">
                <a class="collapse" href="javascript:;"></a>
                <a class="remove" href="javascript:;"></a>
            </div>
        </div>
        <div class="portlet-body">
            <table class="table table-condensed table-hover">
                <tr>
                    <th>订单产品ID</th>
                    <th>订单ID</th>
                    <th>产品ID</th>
                    <th>产品名称</th>
                    <th>购买数量</th>
                    <th>退货数量</th>
                    <th>换货数量</th>
                    <th>价格(销售价/着想价/供应价)</th>
                    <th>实际应付（元）</th>
                    <th>购买形式</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                </tr>
                <?php if ($orderProductInfo->num_rows() > 0) : ?>
                    <?php foreach ($orderProductInfo->result() as $product) : ?>
                        <tr>
                            <td><?php echo $product->order_product_id; ?></td>
                            <td><?php echo $product->order_id; ?></td>
                            <td><?php echo $product->goods_attr_id; ?></td>
                            <td>
                                <strong><?php echo $product->goods_name; ?></strong><br />
                                <?php echo $product->attribute_value; ?>
                            </td>
                            <td><?php echo $product->number; ?></td>
                            <td><?php echo bcsub($product->number, $product->refund_num, 0); ?></td>
                            <td><?php echo $product->barter_num; ?></td>
                            <td><?php echo $product->market_price; ?> / <?php echo $product->shop_price; ?> / <?php echo $product->supply_price; ?></td>
                            <td><?php echo $product->pay_amount; ?></td>
                            <td><?php echo $product->calculate_method == 1 ? '分润' : '议价'; ?></td>
                            <td><?php echo $product->created_at; ?></td>
                            <td><?php echo $product->updated_at; ?></td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </table>
        </div>
    </div>
    <div class="row-fluid">
        <div class="span6">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-picture"></i>用户分润</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body">
                    <table class="table table-condensed table-hover">
                        <tr>
                            <th>订单产品ID</th>
                            <th>用户类型</th>
                            <th>分钱用户</th>
                            <th>账户类型</th>
                            <th>金额（元）</th>
                            <th>资金流向</th>
                        </tr>
                        <?php if ($profit->num_rows() > 0) : ?>
                            <?php foreach ($profit->result() as $item) : ?>
                                <tr>
                                    <td><?php echo $item->order_product_id; ?></td>
                                    <td><?php echo $item->type_name; ?></td>
                                    <td><?php echo $item->user_name . '/' . $item->alias_name; ?></td>
                                    <td><?php echo ($item->account_type == 1) ? '提现' : '月结'; ?></td>
                                    <td><?php echo $item->account; ?></td>
                                    <td><?php echo ($item->as == 1) ? '入账' : '出账'; ?></td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </table>
                </div>
            </div>
        </div>
        <div class="span6">
            <div class="portlet box green">

                <div class="portlet-title">
                    <div class="caption">
                        <i class="icon-picture"></i>
                        <span>物流：<?php if($express->num_rows() > 0){echo $express->row()->name;}  ?></span>
                        <span>快递单号：<?php echo $orderInfo->logistics ?></span>
                    </div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body">
                    <?php if($orderInfo->order_status > 3): ?>
                    <table class="table table-condensed table-hover">
                    <tr>
                        <th>时间</th>
                        <th>地点和跟踪进度</th>
                    </tr>
                    <?php if($logistics->num_rows() > 0): ?>
                    <?php $logistics = $logistics->row(); ?>
                        <?php if($logistics->context): ?>
                        <?php $data = json_decode($logistics->context); ?>
                            <?php foreach($data as $value): ?>
                                <tr>
                                    <td><?php echo $value->time; ?></td>
                                    <td><?php echo $value->context; ?></td>
                                </tr>
                            <?php endforeach ?>
                        <?php endif ?>
                    <?php else: ?>
                    <tr>
                        <td>快递未订阅成功</td>
                        <td><a href="<?php echo base_url('tourismorder/expressRecord/'.$orderInfo->order_id) ?>">从新订阅</a></td>
                    </tr>
                    <?php endif ?>
                    <?php else: ?>
                        未发货
                    <?php endif ?>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="form-actions">
    <a href="<?php echo base_url('tourismorder/grid') ?>">
        <button class="btn" type="button">返回</button>
    </a>
</div>

<script type="text/javascript">
$(document).ready(function(){
    $('.edit-price').click(function(){
        $('.original-price').hide();
        $('.new-price').show().children('input[name=transport_cost]').focus();
    });
    $('.order-note-one').on('click','.edit-order-note',function(){
        $('.order-note-one').hide();
        $('.order-note-two').show().children('input[name=order_note]').focus();
    });
    $('.sale-num').on('click','.save-order-note',function(){
        var orderNote = $('input[name=order_note]').val();
        $.ajax({
        	type: 'post',
            async: true,
            dataType: 'json',
            url: hostUrl() + '/tourismorder/modifyOrderNote',
            data:{'order_note':orderNote,'order_id':$('input[name=order_note_id]').val()},
            success: function (data) {
                if (data.status) {
                    $('.order-note-one').show().children('span').text(orderNote);
                    $('.order-note-two').hide();
                } else {
                    alert(data.messages);
                }
            }
        });
    });
    $('.save-price').click(function(){
        var transportPrice = parseFloat($('input[name=transport_cost]').val());
        $.ajax({
            type: 'post',
            async: true,
            dataType: 'json',
            url: hostUrl() + '/tourismorder/modifyTransport',
            data: {transport_cost:transportPrice,order_id:$('input[name=order_id]').val()},
            success: function (data) {
                if (data.status) {
                    $('.original-price').show().children('span').text(transportPrice);
                    $('.new-price').hide();
                } else {
                    alert(data.messages);
                }
            }
        });
    });
    /*短信提醒 已付款 12小时未发货*/
    $('.send-sms-remind').click(function(){
        var _this = $(this);
        $.ajax({
            type: 'post',
            async: true,
            dataType: 'json',
            url: hostUrl() + '/tourismorder/sendSmsRemind',
            data: {order_id:$(this).attr('data-order-id')},
            beforeSend: function () {
                _this.text('正在发送中...').attr('disabled',true);
            },
            success: function (data) {
                if (data.status) {
                    _this.text('已发送');
                } else {
                    _this.text(data.messages).attr('disabled',false);
                }
            }
        });
    });
});
</script>
<?php $this->load->view('layout/footer'); ?>